package pages;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.Assert;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by WHOover on 07.07.2014.
 */
public class ComparePage extends BasePage {
    private static final By keyLocator = By.xpath("//td[@class='detail-title']");
    private static final String valueLocator = "//td[@class='detail-title']/ancestor::tr/td[%d]";
    private static final By tableContentLocator1 = By.xpath("//div[@class='scroll']/table/tbody/tr");
    private static final String tableContentLocator2 = "//div[@class='scroll']/table/tbody/tr[%d]/td[%d]";

    public ComparePage(WebDriver driver)
    {
        super(driver);
    }

    public boolean isOpened() {
        return driver.getCurrentUrl().equals(URL);
    }

    public Map<String, String> getParameters(int number) {
        ComparePage page = new ComparePage(driver);

        Map<String, String> parameters = new HashMap<String, String>();

        for ( int i = 1; i <= driver.findElements(tableContentLocator1).size(); i++ ) {
            parameters.put(driver.findElement(By.xpath(String.format(tableContentLocator2, i, number))).getText(), driver.findElement(By.xpath(String.format(tableContentLocator2, i, number+1))).getText());
        }

        return parameters;
    }
}
